<template>
  <div class="app-container">


   <h3> 用户列表</h3>

    <!--    查询条件  -->
    <el-form :inline="true" class="demo-form-inline">

      <el-form-item label="基础信息">

        <el-form-item>
          <el-input v-model="userQuery.name" placeholder="姓名"/>
        </el-form-item>
        <el-form-item>
          <el-input v-model="userQuery.email" placeholder="邮箱"/>
        </el-form-item>


        <el-form-item label="高级信息">


          <el-form-item>
            <el-input v-model="userQuery.phone" placeholder="手机号"/>
          </el-form-item>

          <el-form-item>

            <el-input v-model="userQuery.ssn" placeholder="身份证"/>
          </el-form-item>


        </el-form-item>


        <el-button type="primary" icon="el-icon-search" @click="getList()">查 询</el-button>

        <el-button type="default" @click="resetData()">清空</el-button>
      </el-form-item>
    </el-form>

    <div class="cards">
      <el-card class="card" v-for="(item,index) in list" :key="item.id" style="width: 30%">
        <div slot="header" class="clearfix ">
          <div class="head">
            <div class="head_name">
              <el-avatar :src="item.avatar"></el-avatar>
              <span>{{ item.name }} </span>
            </div>
            <div class="buttons">
              <router-link :to="'/user/edit/user/'+item.id">
                <el-button type="primary" size="mini" icon="el-icon-edit" @click="updatePlane()">修改</el-button>
              </router-link>

              <el-button
                type="danger"
                size="mini"
                icon="el-icon-delete"
                @click="removeDataById(item.id)">删除
              </el-button>
            </div>
          </div>
        </div>
        <div class="message_acl">
          <div class="message">
            <el-tag>姓名：{{ item.name }}</el-tag>
            <el-tag>手机号：{{ item.phone }}</el-tag>
            <el-tag>邮箱：{{ item.email }}</el-tag>
          </div>
          <hr/>
          <div class="acl">
            <el-tag>创建时间：{{ item.gmtCreate }}</el-tag>
            <el-tag>修改时间：{{ item.gmtModified }}</el-tag>
            <el-tag>身份证：{{ item.ssn }}</el-tag>
          </div>

        </div>
      </el-card>
    </div>

    <!-- 分页 -->
    <el-pagination
      :current-page="page"
      :page-size="limit"
      :total="total"

      style="padding: 30px 0; text-align: center;"
      layout="total, prev, pager, next, jumper"
      @current-change="getList"
    />
    </div>

</template>

<script>
import user from '@/api/user'

export default {
  name: 'list',
  data() {
    // 定义变量和初始值
    return {
      list: null, // 查询之后接口返回集合
      avatar: '',
      page: 1, // 当前页
      limit: 6, // 每页显示数
      total: 0, // 总记录数
      userQuery: {}, // 条件封装对象

    }
  },
  created() {
    this.getList()
  },
  methods: {

    /**
     * 进入页面打开 查询出所有用户
     * @param page
     */
    getList(page = 1) {
      this.page = page
      user.getUserListPage(this.page, this.limit, this.userQuery)
        .then(response => {
          this.list = response.data.rows
          this.total = response.data.total
        console.log(this.list)
        })
    },

    /**
     * 清除查询
     *
     */
    resetData() {
      this.userQuery = {}
      this.getList()
    },

    /**
     * 根据id删除用户
     * @param id
     */
    removeDataById(id) {
      this.$confirm('此操作将永久删除讲用户记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        user
          .deleteUserId(id)
          .then(response => {
            this.$message({
              type: 'success',
              message: '删除成功!'
            })
            this.getList()
          })
      })
    },

    /**
     * 跳转路由
     */
    updatePlane() {
      this.$router.push({path: '/user/save'})

    }

  }
}
</script>


<style lang="less" scoped>

.cards {
  display: flex;
  flex-direction: row;
  justify-content: space-around;
  flex-wrap: wrap;


  .card {
    display: flex;
    flex-direction: column;
    margin: 10px;

    .message_acl {
      display: flex;
      flex-direction: row;
      justify-content: space-between;
    }

    .message {
      display: flex;
      flex-direction: column;
    }

    .acl{
      display: flex;
      flex-direction: column;

    }


    .head {
      display: flex;
      flex-direction: row;
      justify-content: space-between;
      align-items: flex-end;

    }

  }

}
</style>
